/* Copyright (c) 2004-2008, Andriy Nikolov
 * All rights reserved.
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package org.processmining.analysis.email;

import javax.swing.*;
import org.processmining.framework.ui.*;
import org.processmining.email.*;
import org.processmining.analysis.*;
import org.processmining.framework.plugin.*;
import org.processmining.framework.log.*;
import org.processmining.framework.log.filter.*;
import java.awt.*;
import java.io.*;
import att.grappa.*;
import javax.swing.event.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;

/**
 * <p>An analysis plugin, which converts the imported e-mail log into the
 * process log according to the user's preferences.
 *
 * @author Andriy Nikolov
 * @version 1.0
 */
public class EMailProcessLogAnalysis
    extends JPanel implements AnalysisPlugin, Provider {

  EMailLog eMailLog;
  ProcessLog processLog;
  EMailProcessLogAnalysis EMailProcessLogAnalysis;
  JPanel jPanelResult = new JPanel();
  EMailProcessInstancesListTableModel model;
  JSplitPane jSplitPane1 = new JSplitPane();
  BorderLayout borderLayout100 = new BorderLayout();
  JPanel jPanelProcessInstancesList = new JPanel();
  BorderLayout borderLayout200 = new BorderLayout();
  JScrollPane jScrollPaneProcessInstancesList = new JScrollPane();
  JTable jTableProcessInstancesList = new JTable();
  JPanel jPanelButtons = new JPanel();
  JButton jButtonShow = new JButton();
  ListSelectionModel processInstancesListSelectionModel;
  GrappaPanel grappaPanel = null;
  JScrollPane scrollPaneGraph = new JScrollPane();
  EMailProcessCaseModelGraph modelGraph;
  BorderLayout borderLayout300 = new BorderLayout();

  BorderLayout borderLayout1 = new BorderLayout();
  JTabbedPane jTabbedPaneProcessLog = new JTabbedPane();
  JPanel jPanelCase = new JPanel();
  GridLayout gridLayout1 = new GridLayout();
  JPanel jPanelCaseSources = new JPanel();
  JPanel jPanelCaseList = new JPanel();
  JScrollPane jScrollPaneCaseList = new JScrollPane();
  BorderLayout borderLayout2 = new BorderLayout();
  JPanel jPanelCaseListHeader = new JPanel();
  JPanel jPanelCaseListFooter = new JPanel();
  JList jListCases = new JList();
  JPanel jPanelCaseSourcesOptions = new JPanel();
  BorderLayout borderLayout3 = new BorderLayout();
  JPanel jPanelCaseSourcesHeader = new JPanel();
  JPanel jPanelCaseSourcesFooter = new JPanel();
  JLabel jLabelCases = new JLabel();
  JLabel jLabelCaseList = new JLabel();
  BorderLayout borderLayout4 = new BorderLayout();
  JTextField jTextFieldNewCase = new JTextField();
  JButton jButtonAddCase = new JButton();
  JButton jButtonRemoveCase = new JButton();
  JRadioButton jRadioButtonDefault = new JRadioButton();
  VerticalFlowLayout verticalFlowLayout1 = new VerticalFlowLayout();
  JRadioButton jRadioButtonSender = new JRadioButton();
  JRadioButton jRadioButtonRecipient = new JRadioButton();
  JRadioButton jRadioButtonSingleCase = new JRadioButton();
  JRadioButton jRadioButtonSubject = new JRadioButton();
  JPanel jPanelTask = new JPanel();
  GridLayout gridLayout2 = new GridLayout();
  JPanel jPanelTaskSources = new JPanel();
  JPanel jPanelTaskList = new JPanel();
  BorderLayout borderLayout5 = new BorderLayout();
  JScrollPane jScrollPaneTaskList = new JScrollPane();
  JPanel jPanelTaskListHeader = new JPanel();
  JPanel jPanelTaskListFooter = new JPanel();
  JList jListTasks = new JList();
  JTextField jTextFieldNewTask = new JTextField();
  JButton jButtonRemoveTask = new JButton();
  JButton jButtonAddTask = new JButton();
  BorderLayout borderLayout6 = new BorderLayout();
  JPanel jPanelTaskSourcesOptions = new JPanel();
  JPanel jPanelTaskSourcesHeader = new JPanel();
  JPanel jPanelTaskSourcesFooter = new JPanel();
  BorderLayout borderLayout7 = new BorderLayout();
  JLabel jLabelTaskList = new JLabel();
  JRadioButton jRadioButtonThread = new JRadioButton();
  JButton jButtonPossibleCases = new JButton();
  ButtonGroup buttonGroupCase = new ButtonGroup();
  DefaultListModel caseListModel = new DefaultListModel();
  DefaultListModel taskListModel = new DefaultListModel();
  DefaultListModel taskListAliasesModel = new DefaultListModel();
  DefaultListModel caseListAliasesModel = new DefaultListModel();
  EventTableModel eventTableModel = new EventTableModel();
  ButtonGroup buttonGroupTask = new ButtonGroup();
  VerticalFlowLayout verticalFlowLayout2 = new VerticalFlowLayout();
  JRadioButton jRadioButtonTaskDefault = new JRadioButton();
  JRadioButton jRadioButtonTaskAnywhere = new JRadioButton();
  JCheckBox jCheckBoxAllowPartialCoincidenceTasks = new JCheckBox();
  JCheckBox jCheckBoxIgnoreReplies = new JCheckBox();
  JButton jButtonPossibleTasks = new JButton();
  JCheckBox jCheckBoxAllowPartialCoincidenceCases = new JCheckBox();
  JLabel jLabelTasks = new JLabel();
  JPanel jPanelEvent = new JPanel();
  GridLayout gridLayout3 = new GridLayout();
  JPanel jPanelEventSources = new JPanel();
  BorderLayout borderLayout8 = new BorderLayout();
  JPanel jPanelEventSourceOptions = new JPanel();
  JPanel jPanelEventSourcesHeader = new JPanel();
  JPanel jPanelEventSourcesFooter = new JPanel();
  VerticalFlowLayout verticalFlowLayout3 = new VerticalFlowLayout();
  JCheckBox jCheckBoxAssignEventsAutomatically = new JCheckBox();
  JPanel jPanelEventList = new JPanel();
  BorderLayout borderLayout10 = new BorderLayout();
  JPanel jPanelEventListHeader = new JPanel();
  JPanel jPanelEventListFooter = new JPanel();
  JScrollPane jScrollPaneEventList = new JScrollPane();
  JLabel jLabelEventList = new JLabel();
  JLabel jLabelEventOptions = new JLabel();
  JTable jTableEvents = new JTable();
  BorderLayout borderLayout9 = new BorderLayout();
  JButton jButtonRemoveEvent = new JButton();
  JButton jButtonAddEvent = new JButton();
  JTextField jTextFieldNewEvent = new JTextField();
  ButtonGroup buttonGroupEvent = new ButtonGroup();
  JRadioButton jRadioButtonEventDefault = new JRadioButton();
  JRadioButton jRadioButtonEventSubject = new JRadioButton();
  JRadioButton jRadioButtonEventOneType = new JRadioButton();
  JCheckBox jCheckBoxSaveMessageData = new JCheckBox();
  JRadioButton jRadioButtonAnywhere = new JRadioButton();
  JPanel jPanelTaskAliasesList = new JPanel();
  BorderLayout borderLayout11 = new BorderLayout();
  JPanel jPanelTaskAliasesListHeader = new JPanel();
  JLabel jLabelTaskAliases = new JLabel();
  JPanel jPanelTaskAliasesListFooter = new JPanel();
  BorderLayout borderLayout12 = new BorderLayout();
  JTextField jTextFieldNewTaskAlias = new JTextField();
  JButton jButtonAddTaskAlias = new JButton();
  JButton jButtonRemoveTaskAlias = new JButton();
  JScrollPane jScrollPaneTaskAliases = new JScrollPane();
  JList jListTaskAliases = new JList();
  JPanel jPanelCaseAliasesList = new JPanel();
  JPanel jPanelCaseAliasesListHeader = new JPanel();
  BorderLayout borderLayout13 = new BorderLayout();
  JPanel jPanelCaseAliasesListFooter = new JPanel();
  JScrollPane jScrollPaneCaseAliases = new JScrollPane();
  JList jListCaseAliases = new JList();
  JLabel jLabelCaseAliases = new JLabel();
  JTextField jTextFieldNewCaseAlias = new JTextField();
  BorderLayout borderLayout14 = new BorderLayout();
  JButton jButtonAddCaseAlias = new JButton();
  JButton jButtonRemoveCaseAlias = new JButton();
  JButton jButtonSave = new JButton();
  JButton jButtonLoad = new JButton();
  JPanel jPanelButtonsBottom = new JPanel();
  Border border1 = BorderFactory.createBevelBorder(BevelBorder.RAISED,
      Color.white, Color.white, new Color(103, 101, 98),
      new Color(148, 145, 140));
  FlowLayout flowLayout1 = new FlowLayout();

  /**
   * Basic parameterless constructor for the EMailProcessLogAnalysis plugin
   */
  public EMailProcessLogAnalysis() {
    super();
    try {
      jbInit();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public String getName() {
    return ("E-Mail Process Log Analysis");
  }

  /**
   * Returns the input items needed by this analysis algorithm. The framework
   * uses this information to let the user select appropriate inputs. Input for
   * Process Log Analysis plugin must contain EMailLog object.
   *
   * @return the input items accepted by this analysis algorithm
   */
  public AnalysisInputItem[] getInputItems() {
    AnalysisInputItem[] items = {
      new AnalysisInputItem("E-mail log") {
        public boolean accepts(ProvidedObject object) {
          Object[] o = object.getObjects();
          for(int i=0;i<o.length;i++)
            if(o[i] instanceof EMailLog)
              return true;

          return false;
        }
      }
    } ;
    return items;
  }

  /**
   * Start this analysis algorithm.
   *
   * @param inputs - the inputs chosen by the user
   * @return user interface to the result of the analysis algorithm
   */
  public JComponent analyse(AnalysisInputItem[] inputs) {
    eMailLog = null;
    AnalysisInputItem inputItem;
    ProvidedObject[] pos;
    ProvidedObject po;
    Object[] os;
    Object o;

    inputItem = inputs[0];
    pos = inputItem.getProvidedObjects();
    po = pos[0];
    os = po.getObjects();

    for(int i=0;i<os.length;i++) {
      o = os[i];
      if(o instanceof EMailLog) {
        eMailLog = (EMailLog)o;
        break;
      }
    }

    if(eMailLog==null)
      return null;
    if(processLog==null) {
      processLog = new ProcessLog(eMailLog);
    }
    if(!processLog.getEMailLog().equals(eMailLog)) {
      processLog = new ProcessLog(eMailLog);
    }
    eventTableModel = new EventTableModel(processLog);
    jTableEvents.setModel(eventTableModel);

    return this;
  }

  public void jbInit() {
    this.setMinimumSize(new Dimension(560, 509));
    this.setPreferredSize(new Dimension(560, 509));
    this.setSize(new Dimension(560, 509));
    this.setLayout(borderLayout100);
    jPanelCase.setLayout(gridLayout1);
    jPanelCaseList.setBorder(BorderFactory.createEtchedBorder());
    jPanelCaseList.setLayout(borderLayout2);
    jPanelCaseSources.setBorder(BorderFactory.createEtchedBorder());
    jPanelCaseSources.setLayout(borderLayout3);
    jPanelCaseListFooter.setBorder(BorderFactory.createEtchedBorder());
    jPanelCaseListFooter.setLayout(borderLayout4);
    jPanelCaseSourcesFooter.setBorder(null);
    jLabelCases.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jLabelCases.setText("Cases described by:");
    jLabelCaseList.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jLabelCaseList.setBorder(null);
    jLabelCaseList.setText("Case list");
    jTextFieldNewCase.setText("");
    jButtonAddCase.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonAddCase.setToolTipText("Add new case");
    jButtonAddCase.setText("Add   ");
    jButtonAddCase.addActionListener(new EMailProcessLogAnalysis_jButtonAddCase_actionAdapter(this));
    jButtonRemoveCase.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonRemoveCase.setToolTipText("Remove case");
    jButtonRemoveCase.setText("Remove");
    jButtonRemoveCase.addActionListener(new
        EMailProcessLogAnalysis_jButtonRemoveCase_actionAdapter(this));
    jRadioButtonDefault.setSelected(true);
    jRadioButtonDefault.setText("Linked contact (default)");
    jRadioButtonDefault.addActionListener(new
        EMailProcessLogAnalysis_jRadioButtonDefault_actionAdapter(this));
    jPanelCaseSourcesOptions.setLayout(verticalFlowLayout1);
    jRadioButtonSender.setText("Message sender");
    jRadioButtonSender.addActionListener(new
        EMailProcessLogAnalysis_jRadioButtonSender_actionAdapter(this));
    jRadioButtonRecipient.setText("Message recipient");
    jRadioButtonRecipient.addActionListener(new
        EMailProcessLogAnalysis_jRadioButtonRecipient_actionAdapter(this));
    jRadioButtonSingleCase.setText("Single case (whole log)");
    jRadioButtonSingleCase.addActionListener(new
        EMailProcessLogAnalysis_jRadioButtonSingleCase_actionAdapter(this));
    jRadioButtonSubject.setText("Subject");
    jRadioButtonSubject.addActionListener(new
        EMailProcessLogAnalysis_jRadioButtonSubject_actionAdapter(this));
    jPanelTask.setLayout(gridLayout2);
    jPanelTaskList.setLayout(borderLayout5);
    jButtonRemoveTask.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonRemoveTask.setToolTipText("Remove task type");
    jButtonRemoveTask.setText("Remove");
    jButtonRemoveTask.addActionListener(new
        EMailProcessLogAnalysis_jButtonRemoveTask_actionAdapter(this));
    jButtonAddTask.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonAddTask.setToolTipText("Add new task type");
    jButtonAddTask.setText("Add   ");
    jButtonAddTask.addActionListener(new
        EMailProcessLogAnalysis_jButtonAddTask_actionAdapter(this));
    jPanelTaskListFooter.setLayout(borderLayout6);
    jPanelTaskList.setBorder(BorderFactory.createEtchedBorder());
    jPanelTaskListHeader.setBorder(BorderFactory.createEtchedBorder());
    jPanelTaskListFooter.setBorder(BorderFactory.createEtchedBorder());
    jPanelTaskSources.setLayout(borderLayout7);
    jPanelTaskSources.setBorder(BorderFactory.createEtchedBorder());
    jLabelTaskList.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jLabelTaskList.setText("Task list");
    jRadioButtonThread.setText("Thread (without Re:)");
    jRadioButtonThread.addActionListener(new
        EMailProcessLogAnalysis_jRadioButtonThread_actionAdapter(this));
    jButtonPossibleCases.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonPossibleCases.setToolTipText("Select all possible cases");
    jButtonPossibleCases.setText("Select all possible cases");
    jButtonPossibleCases.addActionListener(new
        EMailProcessLogAnalysis_jButtonPossibleCases_actionAdapter(this));
    jListCases.setModel(caseListModel);
    jListCases.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    jListCases.addMouseListener(new
                                EMailProcessLogAnalysis_jListCases_mouseAdapter(this));
    jListCases.addKeyListener(new EMailProcessLogAnalysis_jListCases_keyAdapter(this));
    jListTasks.setModel(taskListModel);
    jListTasks.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    jListTasks.addMouseListener(new
                                EMailProcessLogAnalysis_jListTasks_mouseAdapter(this));
    jListTasks.addKeyListener(new EMailProcessLogAnalysis_jListTasks_keyAdapter(this));
    jPanelTaskSourcesOptions.setLayout(verticalFlowLayout2);
    jRadioButtonTaskDefault.setSelected(true);
    jRadioButtonTaskDefault.setText("Default (between { and })");
    jRadioButtonTaskDefault.addActionListener(new
        EMailProcessLogAnalysis_jRadioButtonTaskDefault_actionAdapter(this));
    jRadioButtonTaskAnywhere.setText("Anywhere in the subject");
    jRadioButtonTaskAnywhere.addActionListener(new
        EMailProcessLogAnalysis_jRadioButtonTaskAnywhere_actionAdapter(this));
    jCheckBoxAllowPartialCoincidenceTasks.setEnabled(false);
    jCheckBoxAllowPartialCoincidenceTasks.setText("Partial coincidence allowed");
    jCheckBoxAllowPartialCoincidenceTasks.addItemListener(new
        EMailProcessLogAnalysis_jCheckBoxAllowPartialCoincidenceTasks_itemAdapter(this));
    jCheckBoxIgnoreReplies.setText("Count each thread as one event");
    jCheckBoxIgnoreReplies.addItemListener(new
        EMailProcessLogAnalysis_jCheckBoxIgnoreReplies_itemAdapter(this));
    jButtonPossibleTasks.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonPossibleTasks.setToolTipText("Select possible tasks");
    jButtonPossibleTasks.setText("Select possible tasks");
    jButtonPossibleTasks.addActionListener(new
        EMailProcessLogAnalysis_jButtonPossibleTasks_actionAdapter(this));
    jCheckBoxAllowPartialCoincidenceCases.setEnabled(false);
    jCheckBoxAllowPartialCoincidenceCases.setText("Partial coincidence allowed");
    jCheckBoxAllowPartialCoincidenceCases.addItemListener(new
        EMailProcessLogAnalysis_jCheckBoxAllowPartialCoincidenceCases_itemAdapter(this));
    jLabelTasks.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jLabelTasks.setText("Tasks mentioned in");
    jPanelCaseListHeader.setBorder(BorderFactory.createEtchedBorder());
    jPanelEvent.setLayout(gridLayout3);
    jPanelEventSources.setBorder(BorderFactory.createEtchedBorder());
    jPanelEventSources.setLayout(borderLayout8);
    jPanelEvent.setBorder(null);
    jPanelEventSourceOptions.setLayout(verticalFlowLayout3);
    jCheckBoxAssignEventsAutomatically.setActionCommand(
        "Try to insert missing events");
    jCheckBoxAssignEventsAutomatically.setText(
        "Try to insert missing events");
    jCheckBoxAssignEventsAutomatically.addItemListener(new
        EMailProcessLogAnalysis_jCheckBoxAssignEventsAutomatically_itemAdapter(this));
    jPanelEventList.setLayout(borderLayout10);
    jLabelEventList.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jLabelEventList.setText("Event list");
    jLabelEventOptions.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jLabelEventOptions.setText("Event options");
    jPanelEventSourcesHeader.setBorder(null);
    jPanelEventSourceOptions.setBorder(null);
    jPanelEventListHeader.setBorder(BorderFactory.createEtchedBorder());
    jPanelEventListFooter.setBorder(BorderFactory.createEtchedBorder());
    jPanelEventListFooter.setLayout(borderLayout9);
    jPanelEventList.setBorder(BorderFactory.createEtchedBorder());

    jTableEvents.setToolTipText("");
    jTableEvents.addKeyListener(new
                                EMailProcessLogAnalysis_jTableEvents_keyAdapter(this));
    jButtonRemoveEvent.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonRemoveEvent.setToolTipText("Remove event type");
    jButtonRemoveEvent.setText("Remove");
    jButtonRemoveEvent.addActionListener(new
        EMailProcessLogAnalysis_jButtonRemoveEvent_actionAdapter(this));
    jButtonAddEvent.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonAddEvent.setToolTipText("Add new event type");
    jButtonAddEvent.setText("Add   ");
    jButtonAddEvent.addActionListener(new
        EMailProcessLogAnalysis_jButtonAddEvent_actionAdapter(this));
    jTextFieldNewEvent.setText("");
    jRadioButtonEventDefault.setSelected(true);
    jRadioButtonEventDefault.setText("Default (between { and })");
    jRadioButtonEventDefault.addActionListener(new
        EMailProcessLogAnalysis_jRadioButtonEventDefault_actionAdapter(this));
    jRadioButtonEventSubject.setText("Anywhere in the subject");
    jRadioButtonEventSubject.addActionListener(new
        EMailProcessLogAnalysis_jRadioButtonEventSubject_actionAdapter(this));
    jPanelEventSourcesFooter.setBorder(null);
    jRadioButtonEventOneType.setText("One event type (\"normal\")");
    jRadioButtonEventOneType.addActionListener(new
        EMailProcessLogAnalysis_jRadioButtonEventOneType_actionAdapter(this));
    jTabbedPaneProcessLog.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jTabbedPaneProcessLog.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        jTabbedPaneProcessLog_stateChanged(e);
      }
    });
    jCheckBoxSaveMessageData.setText("Include all message data");
    jCheckBoxSaveMessageData.addItemListener(new
        EMailProcessLogAnalysis_jCheckBoxSaveMessageData_itemAdapter(this));
    jRadioButtonAnywhere.setText("Any field");
    jRadioButtonAnywhere.addActionListener(new
        EMailProcessLogAnalysis_jRadioButtonAnywhere_actionAdapter(this));
    jPanelTaskAliasesList.setLayout(borderLayout11);
    jPanelTaskAliasesListHeader.setBorder(BorderFactory.createEtchedBorder());
    jLabelTaskAliases.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jLabelTaskAliases.setText("Aliases");
    jPanelTaskAliasesListFooter.setLayout(borderLayout12);
    jPanelTaskAliasesList.setBorder(BorderFactory.createEtchedBorder());
    jTextFieldNewTaskAlias.setText("");
    jButtonAddTaskAlias.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonAddTaskAlias.setActionCommand("Add");
    jButtonAddTaskAlias.setText("Add");
    jButtonAddTaskAlias.addActionListener(new
        EMailProcessLogAnalysis_jButtonAddTaskAlias_actionAdapter(this));
    jButtonRemoveTaskAlias.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonRemoveTaskAlias.setActionCommand("Remove");
    jButtonRemoveTaskAlias.setText("Remove");
    jButtonRemoveTaskAlias.addActionListener(new
        EMailProcessLogAnalysis_jButtonRemoveTaskAlias_actionAdapter(this));
    jPanelTaskAliasesListFooter.setBorder(BorderFactory.createEtchedBorder());
    jPanelCaseAliasesList.setBorder(BorderFactory.createEtchedBorder());
    jPanelCaseAliasesList.setLayout(borderLayout13);
    jPanelCaseAliasesListHeader.setBorder(BorderFactory.createEtchedBorder());
    jLabelCaseAliases.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jLabelCaseAliases.setText("Aliases");
    jTextFieldNewCaseAlias.setText("");
    jPanelCaseAliasesListFooter.setLayout(borderLayout14);
    jButtonAddCaseAlias.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonAddCaseAlias.setText("Add");
    jButtonAddCaseAlias.addActionListener(new
        EMailProcessLogAnalysis_jButtonAddCaseAlias_actionAdapter(this));
    jButtonRemoveCaseAlias.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonRemoveCaseAlias.setActionCommand("Remove");
    jButtonRemoveCaseAlias.setText("Remove");
    jButtonRemoveCaseAlias.addActionListener(new
        EMailProcessLogAnalysis_jButtonRemoveCaseAlias_actionAdapter(this));
    jPanelCaseAliasesListFooter.setBorder(BorderFactory.createEtchedBorder());
    jListTaskAliases.addKeyListener(new
        EMailProcessLogAnalysis_jListTaskAliases_keyAdapter(this));
    jListCaseAliases.addKeyListener(new
        EMailProcessLogAnalysis_jListCaseAliases_keyAdapter(this));
    jPanelButtons.setBorder(BorderFactory.createEtchedBorder());
    jButtonSave.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonSave.setText("Save");
    jButtonSave.setPreferredSize(new Dimension(61, 25));
    jButtonSave.setSize(new Dimension(61, 25));
    jButtonSave.addActionListener(new
                                EMailProcessLogAnalysis_jButtonSave_actionAdapter(this));
    jButtonLoad.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
    jButtonLoad.setText("Load");
    jButtonLoad.setPreferredSize(new Dimension(61, 25));
    jButtonSave.setMaximumSize(new Dimension(61, 25));
    jButtonSave.setSize(new Dimension(61, 25));
    jButtonLoad.addActionListener(new
                                EMailProcessLogAnalysis_jButtonLoad_actionAdapter(this));
    jPanelButtonsBottom.setBorder(BorderFactory.createRaisedBevelBorder());
    jPanelButtonsBottom.setLayout(flowLayout1);
    this.add(jTabbedPaneProcessLog, java.awt.BorderLayout.CENTER);
    jPanelCase.add(jPanelCaseSources);
    jTabbedPaneProcessLog.add(jPanelCase, "Case");
    jPanelCaseList.add(jScrollPaneCaseList, java.awt.BorderLayout.CENTER);
    jPanelCaseList.add(jPanelCaseListHeader, java.awt.BorderLayout.NORTH);
    jPanelCaseListHeader.add(jLabelCaseList);
    jPanelCaseList.add(jPanelCaseListFooter, java.awt.BorderLayout.SOUTH);
    jScrollPaneCaseList.getViewport().add(jListCases);
    jPanelCaseSources.add(jPanelCaseSourcesOptions,
                          java.awt.BorderLayout.CENTER);
    jPanelCaseSourcesOptions.add(jRadioButtonDefault);
    jPanelCaseSourcesOptions.add(jRadioButtonSender);
    jPanelCaseSourcesOptions.add(jRadioButtonRecipient);
    jPanelCaseSourcesOptions.add(jRadioButtonSubject);
    jPanelCaseSourcesOptions.add(jCheckBoxAllowPartialCoincidenceCases);
    jPanelCaseSourcesOptions.add(jRadioButtonAnywhere);
    jPanelCaseSourcesOptions.add(jRadioButtonSingleCase);
    jPanelCaseSourcesOptions.add(jRadioButtonThread);

    jPanelCaseSources.add(jPanelCaseSourcesHeader, java.awt.BorderLayout.NORTH);
    jPanelCaseSourcesHeader.add(jLabelCases);
    jPanelCaseSources.add(jPanelCaseSourcesFooter, java.awt.BorderLayout.SOUTH);
    jPanelCaseSourcesFooter.add(jButtonPossibleCases);
    jPanelCase.add(jPanelCaseList);
    jPanelCase.add(jPanelCaseAliasesList);
    jPanelCaseListFooter.add(jButtonAddCase, java.awt.BorderLayout.WEST);
    jPanelCaseListFooter.add(jTextFieldNewCase, java.awt.BorderLayout.NORTH);
    jPanelCaseListFooter.add(jButtonRemoveCase, java.awt.BorderLayout.EAST);
    jTabbedPaneProcessLog.add(jPanelTask, "Task");
    jPanelTask.add(jPanelTaskSources);
    jPanelTask.add(jPanelTaskList);
    jPanelTaskListHeader.add(jLabelTaskList);
    jScrollPaneTaskList.getViewport().add(jListTasks);
    jPanelTaskList.add(jPanelTaskListFooter, java.awt.BorderLayout.SOUTH);
    jPanelTaskListFooter.add(jTextFieldNewTask, java.awt.BorderLayout.NORTH);
    jPanelTaskListFooter.add(jButtonAddTask, java.awt.BorderLayout.WEST);
    jPanelTaskListFooter.add(jButtonRemoveTask, java.awt.BorderLayout.EAST);
    jPanelTaskSources.add(jPanelTaskSourcesFooter, java.awt.BorderLayout.SOUTH);
    jPanelTaskSourcesFooter.add(jButtonPossibleTasks);
    jPanelTaskSources.add(jPanelTaskSourcesHeader, java.awt.BorderLayout.NORTH);
    jPanelTaskSourcesHeader.add(jLabelTasks);
    jPanelTaskSources.add(jPanelTaskSourcesOptions,
                          java.awt.BorderLayout.CENTER);
    jPanelTaskSourcesOptions.add(jRadioButtonTaskDefault);
    jPanelTaskSourcesOptions.add(jRadioButtonTaskAnywhere);
    jPanelTaskSourcesOptions.add(jCheckBoxAllowPartialCoincidenceTasks);
    buttonGroupCase.add(jRadioButtonDefault);
    buttonGroupCase.add(jRadioButtonRecipient);
    buttonGroupCase.add(jRadioButtonSender);
    buttonGroupCase.add(jRadioButtonSubject);
    buttonGroupCase.add(jRadioButtonSingleCase);
    buttonGroupCase.add(jRadioButtonThread);
    buttonGroupCase.add(jRadioButtonAnywhere);
    buttonGroupTask.add(jRadioButtonTaskDefault);
    buttonGroupTask.add(jRadioButtonTaskAnywhere);
    jTabbedPaneProcessLog.add(jPanelEvent, "Event");
    jPanelEvent.add(jPanelEventSources);
    jPanelEvent.add(jPanelEventList);
    jPanelEventSourceOptions.add(jRadioButtonEventDefault);
    jPanelEventSourceOptions.add(jRadioButtonEventSubject);
    jPanelEventSourceOptions.add(jRadioButtonEventOneType);
    jPanelEventSourceOptions.add(jCheckBoxAssignEventsAutomatically);
    jPanelEventSourceOptions.add(jCheckBoxIgnoreReplies);
    jPanelEventSourceOptions.add(jCheckBoxSaveMessageData);
    jPanelEventSources.add(jPanelEventSourcesHeader,
                           java.awt.BorderLayout.NORTH);
    jPanelEventSourcesHeader.add(jLabelEventOptions);
    jPanelEventSources.add(jPanelEventSourcesFooter,
                           java.awt.BorderLayout.SOUTH);
    jPanelEventSources.add(jPanelEventSourceOptions,
                           java.awt.BorderLayout.CENTER);
    jPanelEventList.add(jScrollPaneEventList, java.awt.BorderLayout.CENTER);
    jScrollPaneEventList.getViewport().add(jTableEvents);
    jPanelEventList.add(jPanelEventListFooter, java.awt.BorderLayout.SOUTH);
    jPanelEventList.add(jPanelEventListHeader, java.awt.BorderLayout.NORTH);
    jPanelEventListHeader.add(jLabelEventList);
    jPanelEventListFooter.add(jTextFieldNewEvent, java.awt.BorderLayout.NORTH);
    jPanelEventListFooter.add(jButtonAddEvent, java.awt.BorderLayout.WEST);
    jPanelEventListFooter.add(jButtonRemoveEvent, java.awt.BorderLayout.EAST);
    buttonGroupEvent.add(jRadioButtonEventDefault);
    buttonGroupEvent.add(jRadioButtonEventSubject);
    buttonGroupEvent.add(jRadioButtonEventOneType);
    jListTaskAliases.setModel(taskListAliasesModel);
    jListTaskAliases.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    jListCaseAliases.setModel(caseListAliasesModel);
    jListCaseAliases.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    jPanelTaskList.add(jScrollPaneTaskList, java.awt.BorderLayout.CENTER);
    jPanelTaskList.add(jPanelTaskListHeader, java.awt.BorderLayout.NORTH);
    jPanelTask.add(jPanelTaskAliasesList);
    jPanelTaskAliasesListHeader.add(jLabelTaskAliases);
    jPanelTaskAliasesList.add(jScrollPaneTaskAliases, java.awt.BorderLayout.CENTER);
    jScrollPaneTaskAliases.getViewport().add(jListTaskAliases);
    jPanelTaskAliasesList.add(jPanelTaskAliasesListFooter,
                              java.awt.BorderLayout.SOUTH);
    jPanelTaskAliasesList.add(jPanelTaskAliasesListHeader,
                              java.awt.BorderLayout.NORTH);
    jPanelTaskAliasesListFooter.add(jTextFieldNewTaskAlias,
                                    java.awt.BorderLayout.NORTH);
    jPanelTaskAliasesListFooter.add(jButtonAddTaskAlias,
                                    java.awt.BorderLayout.WEST);
    jPanelTaskAliasesListFooter.add(jButtonRemoveTaskAlias,
                                    java.awt.BorderLayout.EAST);
    jScrollPaneCaseAliases.getViewport().add(jListCaseAliases);
    jPanelCaseAliasesList.add(jScrollPaneCaseAliases,
                              java.awt.BorderLayout.CENTER);
    jPanelCaseAliasesList.add(jPanelCaseAliasesListHeader,
                              java.awt.BorderLayout.NORTH);
    jPanelCaseAliasesListHeader.add(jLabelCaseAliases);
    jPanelCaseAliasesList.add(jPanelCaseAliasesListFooter,
                              java.awt.BorderLayout.SOUTH);
    jPanelCaseAliasesListFooter.add(jTextFieldNewCaseAlias,
                                    java.awt.BorderLayout.NORTH);
    jPanelCaseAliasesListFooter.add(jButtonAddCaseAlias,
                                    java.awt.BorderLayout.WEST);
    jPanelCaseAliasesListFooter.add(jButtonRemoveCaseAlias,
                                    java.awt.BorderLayout.EAST);

    jPanelProcessInstancesList.setLayout(borderLayout200);
    jButtonShow.setText("Show Process Instance");
//    this.add(jSplitPane1, java.awt.BorderLayout.CENTER);
    jSplitPane1.add(jPanelProcessInstancesList, JSplitPane.LEFT);
    jSplitPane1.add(scrollPaneGraph, JSplitPane.RIGHT);
    jScrollPaneProcessInstancesList.getViewport().add(
        jTableProcessInstancesList);
    processInstancesListSelectionModel = jTableProcessInstancesList.getSelectionModel();
    processInstancesListSelectionModel.addListSelectionListener(new ListSelectionListener() {
      public void valueChanged(ListSelectionEvent e) {
        jTableProcessInstances_selectionValueChanged(e);
      }
    } );

    jButtonShow.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButtonShow_actionPerformed(e);
      }
    });
    jPanelProcessInstancesList.add(jScrollPaneProcessInstancesList,
                                   java.awt.BorderLayout.CENTER);
    jPanelProcessInstancesList.add(jPanelButtons, java.awt.BorderLayout.SOUTH);
    jPanelButtons.add(jButtonShow);
    jTabbedPaneProcessLog.add("Process Log Graph", jSplitPane1);
    this.add(jPanelButtonsBottom, java.awt.BorderLayout.SOUTH);
    jPanelButtonsBottom.add(jButtonSave);
    jPanelButtonsBottom.add(jButtonLoad);
  }

  public void refreshFrame() {
    updateListCases();
    updateListTasks();

    switch (processLog.getCaseSourceType()) {
      case ProcessLog.CASE_LINKED_CONTACT:
        jRadioButtonDefault.setSelected(false);
        break;
      case ProcessLog.CASE_SENDER:
        jRadioButtonSender.setSelected(false);
        break;
      case ProcessLog.CASE_RECIPIENT:
        jRadioButtonRecipient.setSelected(false);
        break;
      case ProcessLog.CASE_SINGLE_CASE:
        jRadioButtonSingleCase.setSelected(false);
        break;
      case ProcessLog.CASE_SUBJECT:
        jRadioButtonSubject.setSelected(true);
        jCheckBoxAllowPartialCoincidenceCases.setEnabled(true);
        break;
      case ProcessLog.CASE_ANYWHERE:
        jRadioButtonAnywhere.setSelected(true);
        jCheckBoxAllowPartialCoincidenceCases.setEnabled(true);
        break;
      case ProcessLog.CASE_THREAD:
        jRadioButtonThread.setSelected(true);
        jCheckBoxAllowPartialCoincidenceCases.setEnabled(false);
        break;
    }
    System.out.println(processLog.isPartialCoincidenceCasesAllowed());
    jCheckBoxAllowPartialCoincidenceCases.setSelected(processLog.
        isPartialCoincidenceCasesAllowed());

    switch (processLog.getTaskSourceType()) {
      case ProcessLog.TASK_DEFAULT:
        jRadioButtonTaskDefault.setSelected(true);
        jCheckBoxAllowPartialCoincidenceTasks.setEnabled(false);
        break;
      case ProcessLog.TASK_SUBJECT:
        jRadioButtonTaskAnywhere.setSelected(true);
        jCheckBoxAllowPartialCoincidenceTasks.setEnabled(true);
        break;
    }
    jCheckBoxAllowPartialCoincidenceTasks.setSelected(processLog.
        isPartialCoincidenceTasksAllowed());

    switch (processLog.getEventSourceType()) {
      case ProcessLog.EVENT_DEFAULT:
        jRadioButtonEventDefault.setSelected(true);
        jCheckBoxAssignEventsAutomatically.setEnabled(true);
        break;
      case ProcessLog.EVENT_ONETYPE:
        jRadioButtonEventOneType.setSelected(true);
        jCheckBoxAssignEventsAutomatically.setEnabled(false);
        break;
      case ProcessLog.EVENT_SUBJECT:
        jRadioButtonEventSubject.setSelected(true);
        jCheckBoxAssignEventsAutomatically.setEnabled(true);
        break;
    }
    jCheckBoxAssignEventsAutomatically.setSelected(processLog.
                                                   hasToAssignMissingEvents());
    jCheckBoxSaveMessageData.setSelected(processLog.hasToSaveMessageData());
    jCheckBoxIgnoreReplies.setSelected(processLog.isIgnoreReplies());
  }

  private void jTableProcessInstances_selectionValueChanged(ListSelectionEvent e) {
    ProcessCase curCase;
    int index;
    index = processInstancesListSelectionModel.getMinSelectionIndex();
    if(index<0)
      return;
    curCase = (ProcessCase)processLog.getOrderedCaseList().get(index);
    modelGraph = new EMailProcessCaseModelGraph(curCase);
    if(grappaPanel!=null)
      scrollPaneGraph.getViewport().remove(grappaPanel);
    grappaPanel = modelGraph.getGrappaVisualization();
    scrollPaneGraph.getViewport().add(grappaPanel);
    scrollPaneGraph.revalidate();
  }

  public String getHtmlDescription() {
      return "...";
  }

  /**
   * converts the process log mined by the plugin into the LogReader object,
   * which can be processed by mining plugins
   *
   * @return LogReader object containing the process log mined from the e-mail
   *   log
   */
  public LogReader getLogReader() {
    File tmpFile;
    LogReader logReader, newLogReader;
    DefaultLogFilter dlf;
    LogFile logFile;
    int[] indices;
    PrintWriter pw;
    try {
      tmpFile = File.createTempFile("proclog", ".xml");
      pw = new PrintWriter(new BufferedWriter(new FileWriter(tmpFile)));
      processLog.save(pw);
      pw.close();
      logFile = LogFile.getInstance(tmpFile.getAbsolutePath());
      dlf = new DefaultLogFilter(DefaultLogFilter.INCLUDE);
//      logReader = new LogReader(dlf, logFile);
      logReader = LogReaderFactory.createInstance(dlf, logFile);
      indices = new int[logReader.getLogSummary().getNumberOfProcessInstances()];
      for(int i=0;i<indices.length;i++) {
        indices[i]=i;
      }
//      newLogReader = new LogReader(logReader, indices);
      newLogReader = LogReaderFactory.createInstance(logReader, indices);
      return newLogReader;
    } catch (Exception e) {
      Message.add("Error while writing the process log: " + e.getMessage(), Message.ERROR);
      e.printStackTrace();
      return null;
    }
  }

  /**
   * Returns objects provided by the plugin - a ProcessLog object and a
   * LogReader object representing mined process log
   *
   * @return ProvidedObject[] contains two objects both representing the mined
   *   process log:
   *   - org.processmining.email.ProcessLog;
   *   - org.processmining.framework.log.LogReader.
   */
  public ProvidedObject[] getProvidedObjects()
  {
    return (new ProvidedObject[] {
      new ProvidedObject("Process log", new Object[] {
        processLog, getLogReader()
      })
    });
  }

  public void jRadioButtonDefault_actionPerformed(ActionEvent e) {
    processLog.setCaseSourceType(ProcessLog.CASE_LINKED_CONTACT);
    jCheckBoxAllowPartialCoincidenceCases.setEnabled(false);
  }

  public void jRadioButtonSender_actionPerformed(ActionEvent e) {
    processLog.setCaseSourceType(ProcessLog.CASE_SENDER);
    jCheckBoxAllowPartialCoincidenceCases.setEnabled(false);
  }

  public void jRadioButtonRecipient_actionPerformed(ActionEvent e) {
    processLog.setCaseSourceType(ProcessLog.CASE_RECIPIENT);
    jCheckBoxAllowPartialCoincidenceCases.setEnabled(false);
  }

  public void jRadioButtonSubject_actionPerformed(ActionEvent e) {
    processLog.setCaseSourceType(ProcessLog.CASE_SUBJECT);
    jCheckBoxAllowPartialCoincidenceCases.setEnabled(true);
  }

  public void jRadioButtonSingleCase_actionPerformed(ActionEvent e) {
    processLog.setCaseSourceType(ProcessLog.CASE_SINGLE_CASE);
    jCheckBoxAllowPartialCoincidenceCases.setEnabled(false);
  }

  public void jRadioButtonThread_actionPerformed(ActionEvent e) {
    processLog.setCaseSourceType(ProcessLog.CASE_THREAD);
    jCheckBoxAllowPartialCoincidenceCases.setEnabled(false);
  }

  public void jButtonPossibleCases_actionPerformed(ActionEvent e) {
    processLog.extractAllPossibleCases();
    updateListCases();
  }

  public void updateListCases() {
    ProcessCase curCase;
    caseListModel.clear();
    for (int i=0;i<processLog.getOrderedCaseList().size();i++) {
      curCase = (ProcessCase)processLog.getOrderedCaseList().get(i);
      caseListModel.addElement(curCase.getDescription());
    }
  }

  public void jButtonRemoveCase_actionPerformed(ActionEvent e) {
    int index;
    for(index=jListCases.getSelectedIndices().length-1;index>=0;index--) {
      processLog.removeCase(jListCases.getSelectedIndices()[index]);
    }
    updateListCases();
//    index = jListCases.getMinSelectionIndex();
//    processLog.removeCase(index);
//    caseListModel.removeElementAt(index);
  }

  public void jButtonAddCase_actionPerformed(ActionEvent e) {
    String name;
    name = jTextFieldNewCase.getText();
    if(!name.equals("")) {
      processLog.addCase(name);
      caseListModel.addElement(name);
    }
    jTextFieldNewCase.setText("");
  }

  public void jRadioButtonTaskDefault_actionPerformed(ActionEvent e) {
    jCheckBoxAllowPartialCoincidenceTasks.setEnabled(false);
    jCheckBoxAllowPartialCoincidenceTasks.setSelected(false);
    processLog.setTaskSourceType(ProcessLog.TASK_DEFAULT);
  }

  public void jButtonShow_actionPerformed(ActionEvent e) {
   jTableProcessInstances_selectionValueChanged(null);
  }

  public void jRadioButtonTaskAnywhere_actionPerformed(ActionEvent e) {
    jCheckBoxAllowPartialCoincidenceTasks.setEnabled(true);
    jCheckBoxAllowPartialCoincidenceTasks.setSelected(processLog.isPartialCoincidenceTasksAllowed());
    processLog.setTaskSourceType(ProcessLog.TASK_SUBJECT);
  }

  public void jCheckBoxAllowPartialCoincidenceCases_itemStateChanged(ItemEvent
      e) {
    if(e.getStateChange()==ItemEvent.SELECTED) {
      processLog.setPartialCoincidenceCasesAllowed(true);
    } else {
      processLog.setPartialCoincidenceCasesAllowed(false);
    }
  }

  public void jCheckBoxIgnoreReplies_itemStateChanged(ItemEvent e) {
    if(e.getStateChange()==ItemEvent.SELECTED) {
      processLog.setIgnoreReplies(true);
    } else {
      processLog.setIgnoreReplies(false);
    }
  }

  public void jCheckBoxAllowPartialCoincidenceTasks_itemStateChanged(ItemEvent
      e) {
    if(e.getStateChange()==ItemEvent.SELECTED) {
      processLog.setPartialCoincidenceTasksAllowed(true);
    } else {
      processLog.setPartialCoincidenceTasksAllowed(false);
    }
  }

  public void updateListTasks() {
    taskListModel.clear();
    for(int i=0;i<processLog.getTaskTypesList().size();i++) {
      taskListModel.addElement(processLog.getTaskType(i).getName());
    }
  }

  public void jButtonPossibleTasks_actionPerformed(ActionEvent e) {
    processLog.extractPossibleTaskTypes();
    updateListTasks();
  }

  public void jButtonAddTask_actionPerformed(ActionEvent e) {
    String name;
    name = jTextFieldNewTask.getText();
    if(!name.equals("")) {
      processLog.addTaskType(name);
      taskListModel.addElement(name);
    }
    jTextFieldNewTask.setText("");
  }

  public void jButtonRemoveTask_actionPerformed(ActionEvent e) {
    int i;
    for(i=jListTasks.getSelectedIndices().length-1;i>=0;i--) {
      processLog.removeTaskType(jListTasks.getSelectedIndices()[i]);
    }
    updateListTasks();
  }

  public void jButtonAddEvent_actionPerformed(ActionEvent e) {
    String name = jTextFieldNewEvent.getText();
    processLog.addEventType("unknown", name);
    jTextFieldNewEvent.setText("");
  }

  public void jButtonRemoveEvent_actionPerformed(ActionEvent e) {
    int index;
    index = jTableEvents.getSelectedRow();
    processLog.removeEventType(index);
  }

  public void jCheckBoxAssignEventsAutomatically_itemStateChanged(ItemEvent e) {
    if(e.getStateChange()==ItemEvent.SELECTED) {
      processLog.setHasToAssignMissingEvents(true);
    } else {
      processLog.setHasToAssignMissingEvents(false);
    }
  }

  public void jRadioButtonEventDefault_actionPerformed(ActionEvent e) {
    processLog.setEventSourceType(ProcessLog.EVENT_DEFAULT);
    jCheckBoxAssignEventsAutomatically.setEnabled(true);
  }

  public void jRadioButtonEventSubject_actionPerformed(ActionEvent e) {
    processLog.setEventSourceType(ProcessLog.EVENT_SUBJECT);
    jCheckBoxAssignEventsAutomatically.setEnabled(true);
  }

  public void jButtonPossibleEvents_actionPerformed(ActionEvent e) {

  }

  public void jRadioButtonEventOneType_actionPerformed(ActionEvent e) {
    processLog.setEventSourceType(ProcessLog.EVENT_ONETYPE);
    jCheckBoxAssignEventsAutomatically.setEnabled(false);
  }

  public void jCheckBoxSaveMessageData_itemStateChanged(ItemEvent e) {
    if(e.getStateChange()==ItemEvent.SELECTED) {
      processLog.setHasToSaveMessageData(true);
    } else {
      processLog.setHasToSaveMessageData(false);
    }

  }

  public void jRadioButtonAnywhere_actionPerformed(ActionEvent e) {
    processLog.setCaseSourceType(ProcessLog.CASE_ANYWHERE);
    jCheckBoxAllowPartialCoincidenceCases.setEnabled(true);
  }

  public void this_keyPressed(KeyEvent e) {

  }

  public void jListCases_keyPressed(KeyEvent e) {
    if(e.getKeyCode()==KeyEvent.VK_DELETE) {
      jButtonRemoveCase_actionPerformed(null);
    }
  }

  public void jListTasks_keyPressed(KeyEvent e) {
    if(e.getKeyCode()==KeyEvent.VK_DELETE) {
      jButtonRemoveTask_actionPerformed(null);
    }
  }

  public void jTableEvents_keyPressed(KeyEvent e) {
    if(e.getKeyCode()==KeyEvent.VK_DELETE) {
      jButtonRemoveEvent_actionPerformed(null);
    }

  }

  public void jButtonAddCaseAlias_actionPerformed(ActionEvent e) {
    String name, caseSelected;
    ProcessCase selectedCase;

    try {
      caseSelected = (String) jListCases.getSelectedValue();
      selectedCase = (ProcessCase) processLog.getCaseList().get(caseSelected);
      name = jTextFieldNewCaseAlias.getText();
      if ((!name.equals(""))&&(!selectedCase.hasAlias(name))) {
        selectedCase.addAlias(name);
        caseListAliasesModel.addElement(name);
      }
      jTextFieldNewCaseAlias.setText("");
    } catch (Exception exc) {

    }
  }

  public void jButtonRemoveCaseAlias_actionPerformed(ActionEvent e) {
    int i;
    ProcessCase selectedCase;
    String caseSelected;
    caseSelected = (String) jListCases.getSelectedValue();
    selectedCase = (ProcessCase)processLog.getCaseList().get(caseSelected);
    for(i=jListCaseAliases.getSelectedIndices().length-1;i>=0;i--) {
      if(selectedCase.removeAlias(jListCaseAliases.getSelectedIndices()[i])) {
        caseListAliasesModel.removeElementAt(jListCaseAliases.getSelectedIndices()[i]);
      } else {
        JOptionPane.showMessageDialog(this, "The main name cannot be deleted");
      }
    }
  }

  public void jButtonAddTaskAlias_actionPerformed(ActionEvent e) {
    String name, taskSelected;
    ProcessTaskType selectedTask;

    try {
      taskSelected = (String) jListTasks.getSelectedValue();
      selectedTask = (ProcessTaskType) processLog.getTaskTypeByName(taskSelected);
      name = jTextFieldNewTaskAlias.getText();
      if ((!name.equals(""))&&(!selectedTask.hasAlias(name))) {
        selectedTask.addAlias(name);
        taskListAliasesModel.addElement(name);
      }
      jTextFieldNewTaskAlias.setText("");
    } catch (Exception exc) {

    }
  }

  public void jButtonRemoveTaskAlias_actionPerformed(ActionEvent e) {
    int i;
    ProcessTaskType selectedTask;
    String taskSelected;
    try {
      taskSelected = (String) jListTasks.getSelectedValue();
      selectedTask = (ProcessTaskType) processLog.getTaskTypeByName(
          taskSelected);
      for (i = jListTaskAliases.getSelectedIndices().length - 1; i >= 0; i--) {
        if(selectedTask.removeAlias(jListTaskAliases.getSelectedIndices()[
                                         i])) {
               taskListAliasesModel.removeElementAt(jListTaskAliases.getSelectedIndices()[
                                         i]);
        } else {
          JOptionPane.showMessageDialog(this, "The main name cannot be deleted");
        }
      }
    } catch (Exception exc) {

    }
  }

  public void jListTaskAliases_keyPressed(KeyEvent e) {
    if(e.getKeyCode()==KeyEvent.VK_DELETE) {
      jButtonRemoveTaskAlias_actionPerformed(null);
    }
  }

  public void jListCaseAliases_keyPressed(KeyEvent e) {
    if(e.getKeyCode()==KeyEvent.VK_DELETE) {
      jButtonRemoveCaseAlias_actionPerformed(null);
    }
  }

  public void jListCases_mouseClicked(MouseEvent e) {
    ProcessCase selectedCase;
    String caseSelected;
    try {
      caseSelected = (String) jListCases.getSelectedValue();
      selectedCase = (ProcessCase) processLog.getCaseList().get(
          caseSelected);
      caseListAliasesModel.clear();
      for(int i=0;i<selectedCase.getAliases().size();i++) {
        caseListAliasesModel.addElement(selectedCase.getAlias(i));
      }
    } catch(Exception exc) {

    }

  }

  public void jListTasks_mouseClicked(MouseEvent e) {
    ProcessTaskType selectedTask;
    String taskSelected;
    try {
      taskSelected = (String) jListTasks.getSelectedValue();
      selectedTask = (ProcessTaskType) processLog.getTaskTypeByName(
          taskSelected);
      taskListAliasesModel.clear();
      for(int i=0;i<selectedTask.getAliases().size();i++) {
        taskListAliasesModel.addElement(selectedTask.getAlias(i));
      }
    } catch(Exception exc) {

    }
  }

  public void jTabbedPaneProcessLog_stateChanged(ChangeEvent e) {
    if (jTabbedPaneProcessLog.getSelectedIndex()==3) {
      processLog.build();
      model = new EMailProcessInstancesListTableModel(processLog);
      jTableProcessInstancesList.setModel(model);
      jSplitPane1.setDividerLocation(150);
    }
  }

  public void jButtonSave_actionPerformed(ActionEvent e) {
    File file;
    PrintWriter writer;
    int fileChooserValue;
    JFileChooser fileChooser = new JFileChooser();

    if(processLog == null) {
      JOptionPane.showMessageDialog(this, "Create a process log first");
      return;
    }

    fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
    fileChooserValue = fileChooser.showSaveDialog(this);
    if(fileChooserValue==JFileChooser.APPROVE_OPTION) {
      file = fileChooser.getSelectedFile();
      try {
        writer = new PrintWriter(new FileWriter(file));
        processLog.saveSetup(writer);
        writer.close();
      } catch (IOException exc) {
        exc.printStackTrace();
      }
    }
  }

  public void jButtonLoad_actionPerformed(ActionEvent e) {
    File file;
    int messagesLoaded;
    JFileChooser fileChooser = new JFileChooser();

    fileChooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
    fileChooser.setFileFilter(new XMLFileFilter());
    int fileChooserValue = fileChooser.showOpenDialog(this);
    if(fileChooserValue==JFileChooser.APPROVE_OPTION) {
      file = fileChooser.getSelectedFile();
      processLog.loadSetup(file.getAbsolutePath());
      refreshFrame();
//      processWindowEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
    }

  }

}

class EMailProcessLogAnalysis_jListCaseAliases_keyAdapter
    extends KeyAdapter {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jListCaseAliases_keyAdapter(EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void keyPressed(KeyEvent e) {
    adaptee.jListCaseAliases_keyPressed(e);
  }
}

class EMailProcessLogAnalysis_jListCases_keyAdapter
    extends KeyAdapter {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jListCases_keyAdapter(EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void keyPressed(KeyEvent e) {
    adaptee.jListCases_keyPressed(e);
  }
}

class EMailProcessLogAnalysis_jListCases_mouseAdapter
    extends MouseAdapter {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jListCases_mouseAdapter(EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.jListCases_mouseClicked(e);
  }
}

class EMailProcessLogAnalysis_jRadioButtonAnywhere_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jRadioButtonAnywhere_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jRadioButtonAnywhere_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jCheckBoxSaveMessageData_itemAdapter
    implements ItemListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jCheckBoxSaveMessageData_itemAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void itemStateChanged(ItemEvent e) {
    adaptee.jCheckBoxSaveMessageData_itemStateChanged(e);
  }
}

class EMailProcessLogAnalysis_jRadioButtonEventOneType_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jRadioButtonEventOneType_actionAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jRadioButtonEventOneType_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jButtonPossibleEvents_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonPossibleEvents_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonPossibleEvents_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jRadioButtonEventSubject_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jRadioButtonEventSubject_actionAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jRadioButtonEventSubject_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jRadioButtonEventDefault_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jRadioButtonEventDefault_actionAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jRadioButtonEventDefault_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jCheckBoxAssignEventsAutomatically_itemAdapter
    implements ItemListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jCheckBoxAssignEventsAutomatically_itemAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void itemStateChanged(ItemEvent e) {
    adaptee.jCheckBoxAssignEventsAutomatically_itemStateChanged(e);
  }
}

class EMailProcessLogAnalysis_jButtonRemoveEvent_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonRemoveEvent_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonRemoveEvent_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jButtonAddEvent_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonAddEvent_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonAddEvent_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jButtonRemoveTask_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonRemoveTask_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonRemoveTask_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jButtonAddTask_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonAddTask_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonAddTask_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jButtonPossibleTasks_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonPossibleTasks_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonPossibleTasks_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jCheckBoxAllowPartialCoincidenceTasks_itemAdapter
    implements ItemListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jCheckBoxAllowPartialCoincidenceTasks_itemAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void itemStateChanged(ItemEvent e) {
    adaptee.jCheckBoxAllowPartialCoincidenceTasks_itemStateChanged(e);
  }
}

class EMailProcessLogAnalysis_jCheckBoxAllowPartialCoincidenceCases_itemAdapter
    implements ItemListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jCheckBoxAllowPartialCoincidenceCases_itemAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void itemStateChanged(ItemEvent e) {
    adaptee.jCheckBoxAllowPartialCoincidenceCases_itemStateChanged(e);
  }
}

class EMailProcessLogAnalysis_jRadioButtonTaskAnywhere_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jRadioButtonTaskAnywhere_actionAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jRadioButtonTaskAnywhere_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jRadioButtonTaskDefault_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jRadioButtonTaskDefault_actionAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {

    adaptee.jRadioButtonTaskDefault_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jButtonAddCase_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonAddCase_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonAddCase_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jButtonRemoveCase_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonRemoveCase_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {

    adaptee.jButtonRemoveCase_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jRadioButtonThread_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jRadioButtonThread_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jRadioButtonThread_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jRadioButtonSingleCase_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jRadioButtonSingleCase_actionAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jRadioButtonSingleCase_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jRadioButtonSubject_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jRadioButtonSubject_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jRadioButtonSubject_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jRadioButtonRecipient_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jRadioButtonRecipient_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jRadioButtonRecipient_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jRadioButtonSender_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jRadioButtonSender_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jRadioButtonSender_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jRadioButtonDefault_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jRadioButtonDefault_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jRadioButtonDefault_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jButtonPossibleCases_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonPossibleCases_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonPossibleCases_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jListTasks_keyAdapter
    extends KeyAdapter {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jListTasks_keyAdapter(EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void keyPressed(KeyEvent e) {
    adaptee.jListTasks_keyPressed(e);
  }
}

class EMailProcessLogAnalysis_jListTasks_mouseAdapter
    extends MouseAdapter {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jListTasks_mouseAdapter(EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.jListTasks_mouseClicked(e);
  }
}

class EMailProcessLogAnalysis_jListTaskAliases_keyAdapter
    extends KeyAdapter {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jListTaskAliases_keyAdapter(EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void keyPressed(KeyEvent e) {
    adaptee.jListTaskAliases_keyPressed(e);
  }
}

class EMailProcessLogAnalysis_jTableEvents_keyAdapter
    extends KeyAdapter {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jTableEvents_keyAdapter(EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void keyPressed(KeyEvent e) {
    adaptee.jTableEvents_keyPressed(e);
  }
}

class EMailProcessLogAnalysis_jButtonRemoveTaskAlias_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonRemoveTaskAlias_actionAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonRemoveTaskAlias_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jButtonAddTaskAlias_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonAddTaskAlias_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonAddTaskAlias_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jButtonRemoveCaseAlias_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonRemoveCaseAlias_actionAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonRemoveCaseAlias_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jButtonAddCaseAlias_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonAddCaseAlias_actionAdapter(EMailProcessLogAnalysis
      adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonAddCaseAlias_actionPerformed(e);
  }
}
class EMailProcessLogAnalysis_jCheckBoxIgnoreReplies_itemAdapter implements ItemListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jCheckBoxIgnoreReplies_itemAdapter(
      EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void itemStateChanged(ItemEvent e) {
    adaptee.jCheckBoxIgnoreReplies_itemStateChanged(e);
  }
}

class EMailProcessLogAnalysis_jButtonSave_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonSave_actionAdapter(EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonSave_actionPerformed(e);
  }
}

class EMailProcessLogAnalysis_jButtonLoad_actionAdapter
    implements ActionListener {
  private EMailProcessLogAnalysis adaptee;
  EMailProcessLogAnalysis_jButtonLoad_actionAdapter(EMailProcessLogAnalysis adaptee) {
    this.adaptee = adaptee;
  }

  public void actionPerformed(ActionEvent e) {
    adaptee.jButtonLoad_actionPerformed(e);
  }
}
